<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login_ctr extends CI_Controller {


	 public function submit() {
	  // authenticate
	  $uname = $this->input->post('username');
	  $pwd = $this->input->post('password');
	  // read user's credentials from db, through Login Model
	  $this->load->model('users_mdl');	
	  $data['users_list'] = $this->users_mdl->get_users();
	 	
	 $flag_logged = FALSE;	
	  foreach ($data['users_list'] as $key => $value)
	  {
	    //	$k = $key; // just for debugging
		$user_name = $value->nom;
		$user_password= $value->pass;
		$user_group = $value->group_nom;
		$pseudo=$value->pseudo;
		
	  	if(($pseudo == $uname) and  ($user_password == $pwd) )
		{
			
			$flag_logged = TRUE;
			//$this->session->set_userdata('login_state', TRUE);
			$newdata = array('user_name'  => $user_name,'user_group' => $user_group,'login_state' => TRUE );
			$this->session->set_userdata($newdata);
			//$this->load->view('main_vew');
			$this->load->view('parametre_vew');
			break;
		}
		//else
		//{
		//	$this->load->view('go'); // no session established, show error message or redirectto login form
	    //		 //redirect( '/' );    // redirect back to login page
		//}
		
	  }

	if (!$flag_logged){
		echo('login failed');
	}
}
     
	 
	

	 public function valider_parametre(){
	  // authenticate
	  $conv= $this->input->post('seuil_convention');
	  $seuill= $this->input->post('seuill');
	   $tab['seuil_convention']=$conv;
	   $tab['seuill']=$seuill;
	   $this->session->set_userdata($tab); // mettre $tab dans une var globale
	   //$x1=$this->session->userdata('val'); //access la var globale val
	   $this->load->view('main_vew');
	  // break;
} 

}

/* End of file login_ctr.php */
/* Location: ./application/controllers/login_ctr.php */